package com.rchat.pocmini.activity.view.location;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * 抽象公共adapter
 *
 * @author mac
 *
 * @param <T>
 */
public abstract class CommonAdapter<T> extends CommonBaseAdapter<T> {

    protected final int mItemLayoutId;

    public CommonAdapter(Context context, List<T> list, int itemLayoutId) {
        super(context, list);
        this.mItemLayoutId = itemLayoutId;
    }

    public CommonAdapter(Context context, T[] array, int itemLayoutId) {
        super(context, array);
        this.mItemLayoutId = itemLayoutId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CommonViewHolder viewHolder = getViewHolder(position, convertView, parent);
        convert(viewHolder, getItem(position), position);
        return viewHolder.getConvertView();

    }

    public abstract void convert(CommonViewHolder holder, final T item, int position);

    protected CommonViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
        return CommonViewHolder.get(mContext, convertView, parent, mItemLayoutId, position);
    }

}

